const GlobalConfigSchema = require('../entity/config/globalconfig');

async function getGlobalConfig (GlobalConfigName) {
    const GlobalConfigModel = new GlobalConfigSchema().getModel();
    return GlobalConfigModel.findOne({ name: GlobalConfigName });
}

async function createGlobalConfig (GlobalConfigName, data) {
    const GlobalConfigEntity = new GlobalConfigSchema();
    return GlobalConfigEntity.getDoc({
        name: GlobalConfigName,
        data
    }).save();
}

async function updateGlobalConfig (GlobalConfigName, data) {
    const GlobalConfigModel = new GlobalConfigSchema().getModel();
    return GlobalConfigModel.findOneAndUpdate({ name: GlobalConfigName }, { data });
}

module.exports = {
    getGlobalConfig,
    createGlobalConfig,
    updateGlobalConfig
};
